package com.pray.praymall.order.vo;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 订单确认页需要用的数据
 *
 * @author 魂悸魄
 * @date 2020/9/25 21:24
 */
@ToString
public class OrderConfirmVo {
    /**
     * 收货地址集合
     */
    @Getter
    @Setter
    private List<MemberAddressVo> address;
    /**
     * 购物项
     */
    @Getter
    @Setter
    private List<OrderItemVo> items;
    /**
     * 积分
     */
    @Getter
    @Setter
    private Integer integration;
    /**
     * 订单总额
     */
    private BigDecimal total;
    /**
     * 应付总额
     */
    private BigDecimal payTotal;

    @Getter
    @Setter
    private Map<Long, Boolean> stocks;

    /**
     * 防重令牌
     */
    @Getter
    @Setter
    private String orderToken;


    public Integer getCount() {
        Integer i = 0;
        if (items != null && items.size() > 0) {
            for (OrderItemVo item : items) {
                i += item.getCount();
            }
        }
        return i;
    }

    public BigDecimal getTotal() {
        BigDecimal total = new BigDecimal("0.00");
        if (items != null && items.size() > 0) {
            for (OrderItemVo item : items) {
                total = total.add(item.getPrice().multiply(BigDecimal.valueOf(item.getCount())));
            }
        }
        return total;
    }

    public BigDecimal getPayTotal() {
        return getTotal();
    }
}
